package thread;

/**
 * 静态方法锁
 *
 *
 */
public class SyncDemo3 {
    public static void main(String[] args) {
        Thread t = new Thread(){
            public void run(){
                Boo.dosome();
            }
        };

        Thread t1 = new Thread(){
            public void run(){
                Boo.dosome();
            }
        };

        t.start();
        t1.start();
    }
}

class Boo{
    //public synchronized static void dosome(){
    public static void dosome() {

        /*
          静态方法中如果使用同步块时，指定的同步监视器对象应当也是类对象
          指定语法:类名.class

         */
        synchronized (Boo.class) {
            try {
                Thread t = Thread.currentThread();
                System.out.println(t.getName() + ":正在执行dosome方法....");
                Thread.sleep(5000);
                System.out.println(t.getName() + ":dosome方法执行完毕");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
